# 导入SQLAlchemy模块
from sqlalchemy import Column, create_engine,String,Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# 创建对象的基类:
Base = declarative_base()
# 定义math对象:
class math(Base):
    # 表名称：
    __tablename__ = 'math'
    # 字段:
    id = Column(String(20), primary_key=True)
    name = Column(String(50))
    ms = Column(Integer)
# 初始化数据库连接:
engine = create_engine('mysql+mysqlconnector://root:password@localhost:3306/score')
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
# 创建session对象:
session = DBSession()
# 创建对象:
lilizong = math(id='001', name='李立宗', ms=88)
zhaosi = math(id='002', name='赵四', ms=99)
xieguangkun  = math(id='003', name='谢广坤', ms=66)
# 添加到session:
session.add(lilizong)
session.add(zhaosi)
session.add(xieguangkun)
# 提交，即保存到数据库:
session.commit()
# 关闭session:
session.close()
